package br.edu.sistemaacademico.facade;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class DataFacade {
   private Calendar         cal = Calendar.getInstance();
   private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

   public DataFacade(){
	   
   }
   public DataFacade(String data)  {
      Date d;
	try {
		d = sdf.parse(data);
	      cal.setTime(d);
	} catch (ParseException e) {e.printStackTrace();}
   } // public DataFacade(String) throws ParseException

   public void add(int dias) { cal.add(Calendar.DAY_OF_MONTH,dias); }

   public void subtract(int dias) { add(dias * -1); }
   
   @Override
   public String toString() { return sdf.format(cal.getTime()); }
   
   public Date getDate(){ return cal.getTime();}
   
   public String getString(Date d){
	   cal.setTime(d);
	   return toString();
   }
   public String getStingGravar(Date d){
	   cal.setTime(d);
	   SimpleDateFormat sdf2 = new SimpleDateFormat("MM/dd/yyyy");
	   return sdf2.format(cal.getTime());
   }
   public void setDataVisao(String data){
	   SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
	   Date d;
	try {
		d = sdf2.parse(data);
		cal.setTime(d);
	} catch (ParseException e) {e.printStackTrace(); }
	      
   }
} // public class DataFacade
